﻿using System;
using System.Collections.Generic;
using System.IO;
using NHibernate.Cfg;
using NHibernate.Dialect;
using Settings = MsSqlCeTest.SchemaGen.Properties.Settings;

namespace MsSqlCeTest.SchemaGen
{
	class Program
	{
		#region Main

		static void Main()
		{
			var filePath = Settings.Default.OutputFile;
			try
			{
				SaveSchema(filePath);
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
				Console.ReadKey();
			}
		}

		#endregion Main

		#region Helpers

		private static void SaveSchema(string filePath)
		{
			using (var streamWriter = File.CreateText(filePath))
			{
				var configuration = new Configuration();
				configuration.Configure();

				var dialect = Dialect.GetDialect(configuration.Properties);
				var createStatements = new List<string>(configuration.GenerateSchemaCreationScript(dialect));

				foreach (var createStatement in createStatements)
				{
					streamWriter.WriteLine(createStatement);
				}
			}
		}

		#endregion Helpers
	}
}
